<template>
	<view class="page">
		<uni-card title="危险源清单">
			<view class="card-box">
				<view class="card-box-t u-border-bottom">
					<view class="card-box-t-item">
						<text class="num">{{ riskInventory.total_num }}</text>
						<text class="txt">应填写人数</text>
					</view>
					<view class="card-box-t-item">
						<text class="num">{{ riskInventory.filled_num }}</text>
						<text class="txt">已填写人数</text>
					</view>
					<view class="card-box-t-item">
						<text class="num red">{{ riskInventory.not_filled_num }}</text>
						<text class="txt">未填写人数</text>
					</view>
				</view>

				<view class="card-box-b" hover-class="hover-class" @tap="openDeptList"><text>按部查看</text></view>
			</view>
		</uni-card>

		<zb-table :show-header="true" :data="tableData" :columns="tableCols" :stripe="true" :border="true"></zb-table>

		<view class="uni-pagination-box">
			<!-- 分页组件 -->
			<uni-pagination show-icon :page-size="pagination.limit" :current="pagination.page" :total="totalNum" @change="onPageChange" />
		</view>
		<!-- <view class="u-m-t-30"><uni-pagination v-model="pagination.page" :pageSize="pagination.limit" showIcon @change="onPageChange" /></view> -->
	</view>
</template>

<script>
export default {
	data() {
		return {
			pagination: {
				page: 1,
				limit: 10
			},
			riskInventory: {
				total_num: 16,
				filled_num: 12,
				not_filled_num: 4
			},
			tableCols: [
				{ name: 'danger_code', label: '编号', type: 'index', fixed: true }, //operation,img,index,selection
				{ name: 'danger_name', label: '危险源名称', fixed: true, width: 160 },
				{ name: 'danger_dept', label: '危险源管理的主责部门', width: 160 },
				{ name: 'danger_major', label: '重大危险源' },
				{ name: 'danger_src', label: '危险源来源' },
				{ name: 'danger_result', label: '可能导致的后果', width: 160 },
				{ name: 'danger_control_measure_now', label: '现有风险控制措施', width: 160 },
				{ name: 'danger_grade_possibility', label: '可能性' },
				{ name: 'danger_grade_severity', label: '严重性' },
				{ name: 'danger_grade_value', label: '风险值' },
				{ name: 'danger_evaluate_grade', label: '风险评价分级', width: 160 },
				{ name: 'danger_control_measure', label: '风险控制措施', width: 160 },
				{ name: 'rest_danger_possibility', label: '可能性' },
				{ name: 'rest_danger_severity', label: '严重性' },
				{ name: 'rest_danger_value', label: '风险值' },
				{ name: 'rest_danger_evaluate_grade', label: '风险评价分级', width: 160 },
				{ name: 'derive_new_danger_src', label: '是否衍生新的危险源', width: 160 }
			],
			tableData: []
		}
	},
	onLoad() {},
	onShow() {
		this.refreshDataList()
	},
	onReady() {},
	methods: {
		onPageChange(e) {
			//e={type,current} current为当前页，type值为：next/prev
			console.log('onPageChange: ', e)
			this.pagination.page = e.current
			this.getRiskList()
		},
		async refreshDataList() {
			this.pagination.page = 1
			await this.getDangerList()
		},
		openDeptList() {
			const url = `/pages/danger/inventory/dept/index`
			uni.navigateTo({
				url
			})
		},
		async getDangerList() {
			const params = {
				page: this.pagination.page,
				size: this.pagination.limit,
				type: 0 //获取列表的类型，1标识上报列表，0标识公示列表
			}

			try {
				const res = await uni.$uu.Api.getDangerList(params)
				console.log(res)
				if (res.code === 100) {
					this.tableData = res.content.map((_, index) => {
						return {
							danger_name: _.name,
							danger_dept: _.dept,
							danger_major: _.isBig,
							danger_src: _.source,
							danger_result: _.result,
							danger_control_measure_now: _.measure,
							danger_grade_possibility: _.riskPossibility,
							danger_grade_severity: _.riskSeverity,
							danger_grade_value: _.riskValue,
							danger_evaluate_grade: _.riskLevel,
							danger_control_measure: _.controlMeasure,
							rest_danger_possibility: _.riskOverPossibility,
							rest_danger_severity: _.riskOverSeverity,
							rest_danger_value: _.riskOverValue,
							rest_danger_evaluate_grade: _.riskOverLevel,
							derive_new_danger_src: _.newSource
						}
					})
				}
			} catch (e) {
				console.log(e)
			}
		}
	}
}
</script>

<style lang="scss" scoped>
@import '~@/common/scss/index.scss';
@import './index.scss';
</style>
